var t, a = require("../../../biliang/scan/scanbar.js"), e = getApp(), s = require("../../../utils/util.js");

Page({
    data: {
        startStopEngine: "紧急停止",
        isstart: !1,
        unload: !0,
        state: "",
        progress: 0,
        payAmount: "",
        addTime: "",
        carNo: "",
        shopName: ""
    },
    onLoad: function(e) {
        t = this, void 0 !== e.shopId && (this.setData({
            shopId: e.shopId,
            serviceOrderId: e.serviceOrderId
        }), t.getOrderInfo()), this.scanBar = new a(), this.scanBar.init([ "" ]);
        var s = wx.getStorageSync("kScreenW");
        t.setData({
            width: s,
            service_title: 26 * s,
            service_title1: 30 * s
        }), this.startScan();
    },
    onShow: function() {},
    engineButtonTap: function() {
        "已结束" != t.data.startStopEngine ? wx.showModal({
            title: "光速洗车",
            content: "您确定要紧急关闭吗\n关闭后本次服务立即结束",
            confirmText: "关闭",
            cancelText: "取消",
            success: function(a) {
                a.confirm ? (t.setData({
                    state: "紧急停止"
                }), t.stopScan(), wx.showToast({
                    title: "洗车已结束"
                })) : a.cancel;
            }
        }) : wx.showToast({
            title: "订单已结束,无需操作",
            icon: "none"
        });
    },
    startScan: function() {
        var a = e.globalData.token;
        this.scanBar.startScan();
        var s = t.data.progress;
        this.timer = setInterval(function() {
            if (wx.request({
                url: e.globalData.url + "wx/car/machineState",
                data: {
                    token: a,
                    shopId: t.data.shopId
                },
                success: function(a) {
                    a.data.state && t.setData({
                        state: a.data.message
                    });
                }
            }), 99 == s && "洗车结束" == t.data.state) t.scanBar.setProgress(++s), t.setData({
                progress: s
            }), wx.showToast({
                title: "洗车已结束"
            }), setTimeout(function() {
                t.pingjia();
            }, 3e3); else if ("异常停止" == t.data.state) t.warnAction(); else if (s < 99) {
                switch (t.data.state) {
                  case "喷洒泡沫":
                    s = 9;
                    break;

                  case "高压预洗":
                    s = 21;
                    break;

                  case "刷洗车头":
                    s = 34;
                    break;

                  case "刷洗车身":
                    s = 46;
                    break;

                  case "刷洗车尾":
                    s = 58;
                    break;

                  case "喷洒亮光蜡":
                    s = 71;
                    break;

                  case "全车风干":
                    s = 86;
                    break;

                  case "二次风干":
                    s = 99;
                    break;

                  case "洗车结束":
                    s = 100;
                }
                t.setData({
                    progress: s
                }), t.scanBar.setProgress(s);
            }
            100 === s && (t.scanBar.stopScan(!0), clearInterval(t.timer), t.setData({
                startStopEngine: "已结束"
            }));
        }.bind(t), 1e3);
    },
    warnAction: function() {
        var a = e.globalData.token;
        this.scanBar.stopScan(!0), this.scanBar.setProgress(0), clearInterval(this.timer), 
        this.record.pauseMuisc(), t.setData({
            startStopEngine: "已结束",
            state: "异常停止"
        }), wx.showModal({
            title: "仁通洗车",
            content: "智能化洗车平台\nTel: 4006046606",
            confirmText: "拨打",
            cancelText: "关闭",
            success: function(t) {
                t.confirm ? wx.makePhoneCall({
                    phoneNumber: "4006046606"
                }) : t.cancel;
            }
        }), s.request(e, "wx/cust/getOneByServiceOrderId", "POST", {
            token: a,
            serviceOrderId: t.data.serviceOrderId
        }, function(t) {
            t.state;
        }, function(t) {});
    },
    stopScan: function() {
        var a = e.globalData.token;
        this.scanBar.stopScan(!0), this.scanBar.setProgress(0), clearInterval(this.timer), 
        this.record.pauseMuisc(), wx.request({
            url: e.globalData.url + "wx/fbox/stop",
            data: {
                token: a,
                shopId: t.data.shopId
            },
            success: function(a) {
                a.data.state && t.setData({
                    startStopEngine: "已结束"
                });
            }
        });
    },
    onUnload: function() {
        this.record.pauseMuisc(), this.scanBar.stopScan(!0), this.scanBar.setProgress(0), 
        clearInterval(this.timer), t.data.unload && wx.switchTab({
            url: "/pages/home/home"
        });
    },
    pingjia: function() {
        this.record.pauseMuisc(), t.setData({
            unload: !1
        }), wx.redirectTo({
            url: "../evaluate/index?shopId=" + t.data.shopId + "&orderId=" + t.data.serviceOrderId
        });
    },
    getOrderInfo: function() {
        var a = e.globalData.token;
        s.request(e, "wx/cust/getOneByServiceOrderId", "POST", {
            token: a,
            serviceOrderId: t.data.serviceOrderId
        }, function(a) {
            a.state && (t.setData({
                carNo: a.data.carNo,
                payAmount: s.convertMath(a.data.payAmount),
                shopName: a.data.shopName,
                addTime: a.data.addTime,
                orderState: a.data.orderState
            }), 5 == a.data.orderState && (console.log("===================状态为5"), t.scanBar.stopScan(!0), 
            t.scanBar.setProgress(0), clearInterval(t.timer), t.record.pauseMuisc(), t.setData({
                unload: !1
            }), wx.redirectTo({
                url: "../evaluate/index?shopId=" + t.data.shopId
            })));
        }, function(t) {});
    },
    contact: function() {
        wx.showModal({
            title: "仁通洗车",
            content: "智能化洗车平台\nTel: 4006046606",
            confirmText: "拨打",
            cancelText: "关闭",
            success: function(t) {
                t.confirm ? wx.makePhoneCall({
                    phoneNumber: "4006046606"
                }) : t.cancel;
            }
        });
    },
    onReady: function() {
        this.record = this.selectComponent("#record");
    },
    onShareAppMessage: function(a) {
        if ("button" == a.from) return {
            title: "分享红包免费洗车",
            path: "/pages/autoWash/share/index?serviceOrderId=" + t.data.serviceOrderId,
            imageUrl: "https://xc.njrentong.com/back/files/default/autowash/bg5.png",
            success: function(t) {
                wx.showShareMenu({
                    withShareTicket: !0
                });
            },
            fail: function(t) {}
        };
    }
});